package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevAccountDao;
import com.sugon.entity.DevAccountEntity;
import com.sugon.service.DevAccountService;
import com.sugon.utils.Constant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.sugon.utils.ShiroUtils.getUserId;

/**
 * 生产设备台账Service实现类
 *
 * @author sugon
 * @date 2019-07-26 15:46:22
 */
@Service("devAccountService")
public class DevAccountServiceImpl implements DevAccountService {

    @Resource
    private DevAccountDao devAccountDao;

    /**
     * @param id 主键
     * @return
     */
    @Override
    public DevAccountEntity queryObject(String id) {
        return devAccountDao.queryObject(id);
    }

    /**
     * 条件查询
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevAccountEntity> queryList(Map<String, Object> map) {
        return devAccountDao.queryList(map);
    }

    /**
     * 条件查询总数
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devAccountDao.queryTotal(map);
    }

    /**
     * 保存
     *
     * @param devAccount 实体
     * @return
     */
    @Override
    public int save(DevAccountEntity devAccount) {
        devAccount.setId(RandomUtil.randomString(32));
        devAccount.setDelFlag(Integer.valueOf(Constant.IS_NOT_DEL));
        devAccount.setCreateUser(getUserId());
        devAccount.setCreateTime(new Date());
        return devAccountDao.save(devAccount);
    }

    /**
     * 更新实体
     *
     * @param devAccount 实体
     * @return
     */
    @Override
    public int update(DevAccountEntity devAccount) {
        devAccount.setUpdateUser(getUserId());
        devAccount.setUpdateTime(new Date());
        return devAccountDao.update(devAccount);
    }

    /**
     * 根据ID删除实体
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        DevAccountEntity devAccount = devAccountDao.queryObject(id);
        devAccount.setDelFlag(Integer.valueOf(Constant.IS_DEL));
        return devAccountDao.update(devAccount);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devAccountDao.deleteBatch(ids);
    }

    /**
     * 业务批量删除
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteRecord(String ids) {
        DevAccountEntity devAccount = devAccountDao.queryObject(ids);
        devAccount.setDelFlag(Integer.valueOf(Constant.IS_DEL));
        return devAccountDao.update(devAccount);
    }
}
